/***************************************************************************
创建者：华磊
 开始时间：               : 2020.1１.09
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   右侧视窗测试用代理类
*                                                                         *
 ***************************************************************************/
#include "rightviewdelegate.h"
#include "hmicommondefine.h"
#include "instructionEnum.h"

//#include <QDebug>

RightViewDelegate::RightViewDelegate(RightView *rightViewIn, GlobalData *globalDateIn,
                                     QObject* parent):QObject(parent)
{
    globalDate = globalDateIn;
    rightView=rightViewIn;

    tmpType = -1;

    initConnect();
}

RightViewDelegate::~RightViewDelegate()
{

}

void RightViewDelegate::initConnect()
{
    connect(rightView,SIGNAL(button1Signal()),this,SLOT(button1Slot()));
    connect(rightView,SIGNAL(button2Signal()),this,SLOT(button2Slot()));
    connect(rightView,SIGNAL(button3Signal()),this,SLOT(button3Slot()));
    connect(rightView,SIGNAL(button4Signal()),this,SLOT(button4Slot()));
    connect(rightView,SIGNAL(button5Signal()),this,SLOT(button5Slot()));
    connect(rightView,SIGNAL(button6Signal()),this,SLOT(button6Slot()));
}

void RightViewDelegate::changeJogAxisName_slot(bool isJointShow, int totalAxisCountIn,
                                               int pageIdIn, int onePageMaxAxisCount)
{

     rightView->changeJogAxisName(isJointShow,  totalAxisCountIn,
                                  pageIdIn,  onePageMaxAxisCount);

}

void RightViewDelegate::changeCurrentAxis(int axisNumber)
{
    setAllAddress();
    if(axisNumber >= 0 && axisNumber <= 6)
    {
        rightView->buttonPictureAddress[axisNumber]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
//        rightView->setCurrentAxis(axisNumber);

//        if(globalDate->tryLock(TRYLOCKTIME))
//        {
            globalDate->currentUseAxis = axisNumber;;
//            globalDate->unlock();
//        }
    }
    rightView->updateView();
}


void RightViewDelegate::button1Slot()
{
    //qDebug()<<"button1ok";
    //rightView->button1Text="upanddown";
    setAllAddress();
    rightView->buttonPictureAddress[0]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
    rightView->updateView();

//    if(globalDate->tryLock(TRYLOCKTIME))
//    {
        globalDate->currentUseAxis = EM_AXIS_1;
//        globalDate->unlock();
//    }

    //emit changeViewIDsignal(MID_VIEW_JOG);
    emit changeViewJog();
}

void RightViewDelegate::button2Slot()
{
    //qDebug()<<"button2ok";
    //rightView->button2Text="swing";
    setAllAddress();
    rightView->buttonPictureAddress[1]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
    rightView->updateView();

//    if(globalDate->tryLock(TRYLOCKTIME))
//    {
        globalDate->currentUseAxis = EM_AXIS_2;
//        globalDate->unlock();
//    }

    //emit changeViewIDsignal(MID_VIEW_JOG);
    emit changeViewJog();
}

void RightViewDelegate::button3Slot()
{
    //qDebug()<<"button3ok";
    //rightView->button3Text="behindandfront";
    setAllAddress();
    rightView->buttonPictureAddress[2]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
    rightView->updateView();

//    if(globalDate->tryLock(TRYLOCKTIME))
//    {
        globalDate->currentUseAxis = EM_AXIS_3;
//        globalDate->unlock();
//    }

    //emit changeViewIDsignal(MID_VIEW_JOG);
    emit changeViewJog();
}

void RightViewDelegate::button4Slot()
{
    //qDebug()<<"button4ok";
    //rightView->button4Text="rotating";
    setAllAddress();
    rightView->buttonPictureAddress[3]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
    rightView->updateView();

//    if(globalDate->tryLock(TRYLOCKTIME))
//    {
        globalDate->currentUseAxis = EM_AXIS_4;
//        globalDate->unlock();
//    }

    //emit changeViewIDsignal(MID_VIEW_JOG);
    emit changeViewJog();
}

void RightViewDelegate::button5Slot()
{
    //qDebug()<<"button5ok";
    //rightView->button5Text="sliping";
    setAllAddress();
    rightView->buttonPictureAddress[4]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
    rightView->updateView();

//    if(globalDate->tryLock(TRYLOCKTIME))
//    {
        globalDate->currentUseAxis = EM_AXIS_5;
//        globalDate->unlock();
//    }

    //emit changeViewIDsignal(MID_VIEW_JOG);
    emit changeViewJog();
}

void RightViewDelegate::button6Slot()
{
    //qDebug()<<"button6ok";
    //rightView->button6Text="empty";
    setAllAddress();
    rightView->buttonPictureAddress[5]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
    rightView->updateView();

//    if(globalDate->tryLock(TRYLOCKTIME))
//    {
        globalDate->currentUseAxis = EM_AXIS_6;
//        globalDate->unlock();
//    }

    //emit changeViewIDsignal(MID_VIEW_JOG);
    emit changeViewJog();
}

void RightViewDelegate::button7Slot()
{
    //qDebug()<<"button6ok";
    //rightView->button6Text="empty";
    setAllAddress();
    rightView->buttonPictureAddress[6]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_p.png";
    rightView->updateView();

//    if(globalDate->tryLock(TRYLOCKTIME))
//    {
        globalDate->currentUseAxis = EM_AXIS_7;
//        globalDate->unlock();
//    }

    //emit changeViewIDsignal(MID_VIEW_JOG);
    emit changeViewJog();
}

void RightViewDelegate::setAllAddress()
{
    for(int i = 0;i<rightView->buttonPictureAddress.size();i++)
    {
        rightView->buttonPictureAddress[i]="/agvwork/AgvHmi/baseBag/hmiProject/resources/rightviewresources/right_empty_n.png";
    }
}
